﻿using System;
using CodePlex.DnD4eCampaignManager.DnD4e;
using CodePlex.DnD4eCampaignManager.DnD4e.Interfaces;
using CodePlex.DnD4eCampaignManager.Presentation.ViewInterfaces;
using CodePlex.DnD4eCampaignManager.Repositories.Interfaces;

namespace CodePlex.DnD4eCampaignManager.Presentation
{
    public class LocationPresenter
    {
        public LocationPresenter(string locationName, ILocationView view, ILocationRepository locationRepository)
        {
            LocationName = locationName;
            View = view;
            LocationRepository = locationRepository;
        }

        public string LocationName { get; set; }
        public ILocationRepository LocationRepository { get; set; }
        public ILocationView View { get; set; }

        public void DisplayLocation()
        {
            View.LocationName = LocationName;

            if ( !LocationRepository.GetAllNames().Contains(LocationName) )
            {
                return;
            }

            ILocation location = LocationRepository.GetByName(LocationName);
            View.LocationDescription = location.Description;
            View.LocationDistances = location.Distances;
            View.LocationNPCs = location.Npcs;
        }

        public void ImportLocationImageFile(string fileName)
        {
            // Use the repository to associate the image with the location
            // Update the image on the location view
            throw new NotImplementedException();
        }

        public void SaveLocation()
        {
            ILocation location = new Location
                                     {
                                         Name = LocationName,
                                         Description = View.LocationDescription,
                                         Distances = View.LocationDistances,
                                         Npcs = View.LocationNPCs
                                     };
            LocationRepository.Save(location);
        }
    }
}